package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author zcf
 */
@Mapper
public interface DishMapper {
    @Insert("insert into dish(category_id, name, price, status, description, image, create_time, create_user, update_time, update_user) " +"VALUES (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image},#{createTime}, #{createUser}, #{updateTime},\n" +
            "#{updateUser})")
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Dish dish);


    List<Dish> pageQuery(DishPageQueryDTO dishPageQueryDTO);


    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);


    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> list(Long categoryId);

    List<Dish> getBySetmealId(Long id);

    @Select("select sd.copies,d.description,d.image,d.name from dish d left join setmeal_dish sd on d.id=sd.dish_id where sd.setmeal_id=#{id}")
    List<DishItemVO> getBySetmealId2(Long id);

    @Select("select count(*) from dish where status = #{status}")
    Integer getByStatus(Integer disable);
}
